package com.xwb.laboratory.test.responsibility;

import java.util.ArrayList;
import java.util.List;

public class MyChain {

	// 要执行的任务列表，
	public List<Responsibility> chainList;
	
	// 索引，用来获取当前要执行哪个任务
	public int i = 0;
	
	public MyChain() {
		chainList = new ArrayList<>();
	}
	
	public void doChain(String param) {
		if(i < chainList.size()) {
			chainList.get(i++).process(param, this);
		}
	}
	
	public void register(Responsibility responsibility) {
		this.chainList.add(responsibility);
	}
}
